import {Component, OnInit} from '@angular/core';
import {NzModalRef} from 'ng-zorro-antd';
import {_HttpClient} from '@delon/theme';
import {SFSchema, SFUISchema} from '@delon/form';

@Component({
  selector: 'app-joa-leave-edit',
  templateUrl: './edit.component.html',
})
export class JoaLeaveEditComponent implements OnInit {
  record: any;
  i: any={};
  updateFlag=false;
  schema: SFSchema = {
    properties: {
      days: {
        type: 'string',
        title: '请假天数'
      },
      reason: {
        type: 'string',
        title: '请假原因'
      },
      type: {
        type: 'string',
        title: '请假类型'
      },
      bpmStatus: {
        type: 'string',
        title: '流程状态'
      },
    },

    required: ['days','reason','type','bpmStatus',],
  };
  ui: SFUISchema = {
    /*    $type:{
          widget:'dict-select',
          dictCode:'leave_type',
        }*/
  };

  constructor(
    private modal: NzModalRef,
    public http: _HttpClient,
  ) {}

  ngOnInit(): void {
    if(this.record){
      this.updateFlag=true;
      this.http.get(`joa/leave/queryById`,{id:this.record.id}).subscribe( (res:any) =>{
        this.i=res.result;
      });
    }

  }

  save(value: any) {
    this.http.post(`joa/leave/add`, value).subscribe(res => {
      this.modal.close(true);
    });
  }
  update(value: any) {
    this.http.put(`joa/leave/edit`, value).subscribe(res => {
      this.modal.close(true);
    });
  }
  saveOrUpdate(value:any){
    if(this.updateFlag){
      this.update(value);
    }else{
      this.save(value);
    }
  }
  close() {
    this.modal.destroy();
  }
}
